package com.company;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.*;
import java.util.List;
import java.util.Vector;

import com.company.ZSGC;
public class qinshi {
    private static String url = "jdbc:oracle:thin:@localhost:1521:XE";
    private static String user="hr";
    private static String password="123456";
    private JPanel panel1;
    private JTextField textField2;
    private JTextField textField3;
    private JTextField textField1;
    private JButton 查询Button;
    private JButton 入住Button;
    private JTable table1;
    private DefaultTableModel table;
    private Object[][] data;
    private String[] total={"寝室","公寓","人数","系别","班级","年级"};
    public qinshi()
    {
        JFrame qin=new JFrame("寝室分配");
        qin.setSize(400,400);
        qin.add(panel1);
        qin.setLocation(400,250);
        qin.setVisible(true);
        查询Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
               String[] STU=new String[3];
               STU[0]=textField1.getText();
               STU[1]=textField2.getText();
               STU[2]=textField3.getText();
               ZSGC zs=new ZSGC();
                try {
                    Connection conn = DriverManager.getConnection(url, user, password);//连接数据库
                    PreparedStatement pst = conn.prepareStatement("select * from dormitory where 系别=? or 班级=? or 年级=? ");//准备执行SQL语句
                    pst.setString(1, STU[0]);
                    pst.setString(2, STU[2]);
                    pst.setString(3, STU[1]);
                    ResultSet rs = pst.executeQuery();
                    int sample = 0;
                    while (rs.next()) {
                        sample++;
                    }
                    String[][] a=zs.chazhao(STU);
                    for(int i=0;i<sample;i++)
                        table.addRow(a[i]);
                    //}

                } catch (SQLException ex) {
                    ex.printStackTrace();
                }
            }

        });
        入住Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
            new ruzhu();
            }
        });
    }

    public static void main(String[] args) {
        qinshi qi=new qinshi();
    }


    private void createUIComponents() {
        // TODO: place custom component creation code here
        data=null;
        table=new DefaultTableModel(data,total);
        table1 = new JTable(table);
    }
}
